﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

class AirportParser {
    public static void Main() {
        Tuple<double, double> ORIGINAL_MAP_DIM = new Tuple<double, double>(900, 420);
        Tuple<double, double> SCALED_MAP_DIM = new Tuple<double, double>(1280, 800);
        double SCALE_X = SCALED_MAP_DIM.Item1 / ORIGINAL_MAP_DIM.Item1;
        double SCALE_Y = SCALED_MAP_DIM.Item2 / ORIGINAL_MAP_DIM.Item2;

        List<Runway> runways = new List<Runway>();
        List<Taxiway> taxiways = new List<Taxiway>();

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load("airport.xml");
        XmlElement xmlRoot = xmlDoc.DocumentElement;
        XmlNodeList xmlRunways = xmlRoot.SelectNodes("/airport/runways/runway");
        XmlNodeList xmlTaxiways = xmlRoot.SelectNodes("/airport/taxiways/taxiway");

        /*
         * <runway direction1="" direction2="">
         *      <maxWeight>
         *      <width>
         *      <arrivals>
         *      <departures>
         *      <labelLocation>
         *      <nodes>
        */
        foreach(XmlNode xmlRunway in xmlRunways) {
            Runway newRunway = new Runway();
            newRunway.Direction1 = xmlRunway.Attributes["direction1"].Value;
            newRunway.Direction2 = xmlRunway.Attributes["direction2"].Value;
            newRunway.MaxWeight = Convert.ToInt32(xmlRunway.ChildNodes[0].InnerText);
            newRunway.Width = Convert.ToInt32(xmlRunway.ChildNodes[1].InnerText);
            newRunway.Arrivals = (xmlRunway.ChildNodes[2].InnerText == "0" ? false : true);
            newRunway.Departures = (xmlRunway.ChildNodes[3].InnerText == "0" ? false : true);
            newRunway.SetLabelLocation(xmlRunway.ChildNodes[4].InnerText, SCALE_X, SCALE_Y);

            foreach(XmlNode xmlRunwayNode in xmlRunway.ChildNodes[5].ChildNodes) {
                newRunway.AddNode(xmlRunwayNode.InnerText, SCALE_X, SCALE_Y);
            }

            runways.Add(newRunway);
        }

        /*
         * <taxiway name="">
         *      <maxWeight>
         *      <width>
         *      <nodes>
        */
        foreach(XmlNode xmlTaxiway in xmlTaxiways) {
            Taxiway newTaxiway = new Taxiway();
            newTaxiway.Name = xmlTaxiway.Attributes["name"].Value;
            newTaxiway.MaxWeight = Convert.ToInt32(xmlTaxiway.ChildNodes[0].InnerText);
            newTaxiway.Width = Convert.ToInt32(xmlTaxiway.ChildNodes[1].InnerText);

            foreach(XmlNode xmlTaxiwayNode in xmlTaxiway.ChildNodes[2].ChildNodes) {
                newTaxiway.AddNode(xmlTaxiwayNode.InnerText, SCALE_X, SCALE_Y);
            }

            taxiways.Add(newTaxiway);
        }

        foreach(Runway runway in runways) {
            Console.WriteLine(runway);
        }

        foreach(Taxiway taxiway in taxiways) {
            Console.WriteLine(taxiway);
        }

        Console.ReadLine();
    }
}
